
#include "Producer_Consumer.hpp"
#include <unistd.h>
#include <time.h>




void* produce(void* args)
{
    BlockQueue<int>* q = (BlockQueue<int>*)args;
    while(1)
    {
        int a = rand();
        q->push(a);
        std::cout << "Produced :" << a << std::endl;
        usleep(100000);   
    }
}

void* consume(void* args)
{
    BlockQueue<int>* q = (BlockQueue<int>*)args;
    while(1)
    {
        int data = q->pop();
        std::cout << "Consumed :" << data << std::endl;
        usleep(1000000);
    }
}




int main()
{
    BlockQueue<int> q;
    srand((unsigned int)time(nullptr));

    pthread_t pt ,ct;
    pthread_create(&ct , nullptr , consume , (void*)&q);
    sleep(2);
    pthread_create(&ct , nullptr , produce , (void*)&q);

    while(1)
    {
        sleep(111);
    }
    return 0;
}